package com.tianshuo.construct.main;

import com.tianshuo.construct.ConstructConfig;
import com.tianshuo.construct.model.Animal;
import com.tianshuo.construct.model.Cat;
import org.springframework.context.annotation.AnnotatedBeanDefinitionReader;
import org.springframework.context.annotation.AnnotationConfigApplicationContext;

/**
 * 直接使用AnnotatedBeanDefinitionReader 配合类读取器，手动注册配置类
 */
public class ConstructApplicationContext {
    public static void main(String[] args) {
        AnnotationConfigApplicationContext applicationContext = new AnnotationConfigApplicationContext();

        // 使用自定义的AnnotatedBeanDefinitionReader来手动注册的配置类
        AnnotatedBeanDefinitionReader annotatedBeanDefinitionReader = new AnnotatedBeanDefinitionReader(applicationContext);
        annotatedBeanDefinitionReader.register(ConstructConfig.class);

        applicationContext.refresh();
        Animal animal = applicationContext.getBean(Animal.class);
        System.out.println(applicationContext.getBean(Cat.class));
        System.out.println(applicationContext.getBean(ConstructConfig.class));

        System.out.println(animal.getCat());


    }
}
